package com.ruoyi.paipan.common;

import com.ruoyi.paipan.utils.ToolUtil;

import java.util.*;

/**
 * @author tiemeng
 * * @date 2024/11/25
 */
public class Cdziwei {
    private ArrayList<List<Object>> mpx = new ArrayList<List<Object>>() {{
        add(Arrays.asList("zw", 0, 4, 1, 1, 2, 6, 2, 1, 1, 2, 4, 5, 2));
        add(Arrays.asList("zw", 1, 1, 6, 2, 2, 1, 4, 1, 6, 4, 2, 1, 4));
        add(Arrays.asList("zw", 2, 6, 6, 2, 1, 2, 2, 1, 4, 5, 5, 6, 6));
        add(Arrays.asList("zw", 3, 2, 1, 5, 6, 1, 4, 2, 1, 4, 2, 1, 4));
        add(Arrays.asList("zw", 4, 2, 6, 5, 1, 4, 1, 6, 6, 2, 4, 4, 1));
        add(Arrays.asList("zw", 5, 4, 2, 1, 5, 2, 6, 4, 1, 1, 4, 2, 6));
        add(Arrays.asList("tf", 0, 1, 1, 1, 4, 1, 4, 2, 1, 4, 6, 1, 2));
        add(Arrays.asList("tf", 1, 1, 1, 5, 6, 5, 6, 6, 4, 4, 2, 2, 1));
        add(Arrays.asList("tf", 2, 2, 1, 4, 3, 1, 6, 2, 1, 4, 4, 1, 6));
        add(Arrays.asList("tf", 3, 2, 2, 1, 1, 4, 4, 2, 6, 1, 1, 2, 2));
        add(Arrays.asList("tf", 4, 1, 1, 1, 6, 2, 4, 2, 5, 1, 6, 5, 4));
        add(Arrays.asList("tf", 5, 1, 2, 1, 1, 2, 6, 1, 2, 6, 3, 2, 6));
        add(Arrays.asList("tf", 6, 2, 1, 1, 6, 2, 4, 2, 2, 1, 5, 1, 4));
        add(Arrays.asList("tf", 7, 1, 2, 6, 2, 2, 5, 1, 1, 6, 6, 2, 4));
        add(Arrays.asList("yganx", 0, 2, -1, 1, 2, -1, 1, 2, -1, 1, 2, -1, 1));
        add(Arrays.asList("yganx", 1, 6, 1, -1, 6, 1, -1, 4, 1, -1, 6, 1, -1));
        add(Arrays.asList("yganx", 2, -1, 1, 6, -1, 1, 6, -1, 1, 6, -1, 1, 6));
        add(Arrays.asList("yganx", 3, -1, -1, 2, -1, -1, 2, -1, 2, 1, 1, -1, -1));
        add(Arrays.asList("yganx", 4, 2, 2, -1, 1, -1, -1, 1, -1, -1, -1, -1, 2));
        add(Arrays.asList("monthx", 0, 2, 1, 1, 6, 1, 4, 2, 1, 4, 6, 1, 5));
        add(Arrays.asList("monthx", 1, 1, 1, 2, 6, 1, 4, 2, 1, 5, 6, 1, 4));
        add(Arrays.asList("hourx", 0, 2, 1, 6, 4, 2, 1, 6, 4, 2, 1, 6, 2));
        add(Arrays.asList("hourx", 1, 1, 1, 4, 2, 1, 1, 6, 2, 4, 1, 6, 2));
        add(Arrays.asList("qitax", 1, 6, 6, 1, 1, 2, 2, 1, 2, 2, 6, 1, 1));
        add(Arrays.asList("qitax", 0, 4, 2, 1, 4, 5, 2, 1, 5, 6, 6, 1, 4));
    }};
    private List<String> mpxzi = Arrays.asList("", "庙", "旺", "地", "平", "闲", "陷");
    private List<String> tiangan = Arrays.asList("癸", "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬");
    private List<String> dizhi = Arrays.asList("亥", "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌");
    private List<String> segong = Arrays.asList("命宫", "兄弟宫", "夫妻宫", "子女宫", "财帛宫", "疾厄宫", "迁移宫", "奴仆宫", "官禄宫", "田宅宫", "福德宫", "父母宫");
    private List<String> boshi = Arrays.asList("博士", "力士", "青龙", "小耗", "将军", "奏书", "飞廉", "喜神", "病符", "大耗", "伏兵", "官府");
    private List<String> changsheng = Arrays.asList("长生", "沐浴", "冠带", "临官", "帝旺", "衰", "病", "死", "墓", "绝", "胎", "养");
    private List<String> liunianxing = Arrays.asList("岁建", "晦气", "丧门", "贯索", "官符", "小耗", "大耗", "龙德", "白虎", "天德", "吊客", "病符");
    private List<String> liunianxing2 = Arrays.asList("将星", "攀鞍", "岁驿", "息神", "华盖", "劫煞", "灾煞", "天煞", "指背", "咸池", "月煞", "亡神");
    public LinkedHashMap<Integer, LinkedHashMap<String, String>> zwxing = new LinkedHashMap<>();
    private List<String> zwxing_s = Arrays.asList("紫", "天", "太", "武", "天", "廉");
    private List<String> zwxing_x = Arrays.asList("微", "机", "阳", "曲", "同", "贞");
    public LinkedHashMap<Integer, LinkedHashMap<String, String>> tfxing = new LinkedHashMap<>();
    private List<String> tfxing_s = Arrays.asList("天", "太", "贪", "巨", "天", "天", "七", "破");
    private List<String> tfxing_x = Arrays.asList("府", "阴", "狼", "门", "相", "梁", "杀", "军");
    private LinkedHashMap<Integer, List<String>> monthx = new LinkedHashMap<>();
    private List<String> monthx_s = Arrays.asList("左", "右", "天", "天", "天", "天", "阴");
    private List<String> monthx_x = Arrays.asList("辅", "弼", "刑", "姚", "月", "巫", "煞");
    private LinkedHashMap<Integer, List<String>> hourx = new LinkedHashMap<>();
    private List<String> hourx_s = Arrays.asList("文", "文", "地", "地", "台", "封");
    private List<String> hourx_x = Arrays.asList("昌", "曲", "空", "劫", "辅", "诰");
    private LinkedHashMap<Integer, List<String>> yganx = new LinkedHashMap<>();
    private List<String> yganx_s = Arrays.asList("禄", "擎", "陀", "天", "天", "天", "天", "正", "副");
    private List<String> yganx_x = Arrays.asList("存", "羊", "罗", "钺", "魁", "福", "官", "空", "空");
    private LinkedHashMap<Integer, List<String>> yzhix = new LinkedHashMap<>();
    private List<String> yzhix_s = Arrays.asList("天", "天", "天", "龙", "凤", "咸", "红", "天", "天", "解", "华", "孤", "寡", "劫", "蜚", "破", "大");
    private List<String> yzhix_x = Arrays.asList("虚", "哭", "空", "池", "阁", "池", "鸾", "喜", "马", "神", "盖", "辰", "宿", "杀", "廉", "碎", "耗");
    private LinkedHashMap<Integer, List<String>> qitax = new LinkedHashMap<>();
    private List<String> qitax_s = Arrays.asList("火", "铃", "三", "八", "天", "恩", "天", "天", "天", "天");
    private List<String> qitax_x = Arrays.asList("星", "星", "台", "座", "贵", "光", "才", "寿", "使", "伤");
    private String se_pre = "<font color=red>";
    private String se_pre1 = "<font color=purple>";
    private String se_pre2 = "<font color=brown>";
    private String se_pre3 = "<font color=gray>";
    private String se_end = "</font>";
    private int sex;
    private int ytgx;
    private int ydzx;
    private int cm;
    private int cd;
    private int hzx;
    public int juxu = 0;
    public boolean is_sun;
    public int csmode;
    public int mgindex = 0;
    public int sgindex = 0;
    public int zwindex = 0;
    public int luindex = 0;
    public int jiang_x;
    private List<String> dptg = new ArrayList<>();
    private LinkedHashMap<Integer, String> minggong = new LinkedHashMap<>();
    private List<String> shengong = new ArrayList<>();
    private int xiaoxian;
    private String juname = "";
    private String sihuaname="";
    private boolean ismobile;

    public Cdziwei(LinkedHashMap<String, Object> parent) {
//        this.ismobile = parent.containsKey("ismobile") && (boolean) parent.get("ismobile");
        this.sex = (Integer) parent.getOrDefault("sex", 0);
        this.csmode = (Integer) parent.getOrDefault("csmode", "");
        this.ytgx = (Integer) parent.getOrDefault("ytgx", 0);
        this.ydzx = (Integer) parent.getOrDefault("ydzx", 0);
        this.cm = (Integer) parent.getOrDefault("cm", "");
        this.cd = (int) parent.getOrDefault("cd", 0);
        this.is_sun = this.isSuni();
        this.jiang_x = (this.ydzx % 4 + (4 - (this.ydzx % 4)) * 4) % 12;
        this.hzx = Integer.parseInt((String) parent.getOrDefault("hzx", ""));
        this.get_dpgan();
        this.get_minggong();
        this.get_zwju();
        this.get_zhengxing();
        this.get_yganx();
        this.get_yzhix();
        this.get_monthx();
        this.get_hourx();
        this.get_qitax();
    }

    private boolean isSuni() {
        return (this.sex == 0 && this.ytgx % 2 == 0) || (this.sex == 1 && this.ytgx % 2 == 1);
    }

    public void get_dpgan() {
        for (int i = 0; i <= 11; i++) {
            int xu = ((this.ytgx % 5) * 2 + 1) % 10;
            int gxu = (xu + (i + 9) % 12) % 10;
            String s = this.tiangan.get(gxu);
            this.dptg.add(s);
        }
    }

    public void get_minggong() {
        int mingx, shenx;
        int mx = (this.cm + 2) % 12;
        this.mgindex = mingx = (mx - this.hzx + 12 + 1) % 12;
        this.sgindex = shenx = (mx + this.hzx - 1) % 12;
        for (int i = 0; i <= 11; i++) {
            int x = (mingx - i + 12) % 12;
            String mgname, sgname;
            if (shenx == x) {
                mgname = ToolUtil.cn_substr(this.segong.get(i), 0, 1);
                sgname = "身";
            } else {
                mgname = this.segong.get(i);
                sgname = "&emsp;";
            }
            if (i == 0) {
                this.minggong.put(x, this.se_pre + sgname + "★" + this.segong.get(i) + this.se_end);
            } else {
                minggong.put(x, this.se_pre + sgname + this.segong.get(i) + this.se_end);
            }
        }
    }

    public void get_zwju() {
        LinkedHashMap<Integer, String> wxju = new LinkedHashMap<Integer, String>() {{
            put(2, "水二");
            put(3, "木三");
            put(4, "金四");
            put(5, "土五");
            put(6, "火六");
        }};
        int zwggan = this.tiangan.indexOf(this.dptg.get(this.mgindex));
        String mgnayin_wx = this.get_nayin_wx(zwggan, this.mgindex);
        for (Integer k : wxju.keySet()) {
            String v = wxju.get(k);
            if (v.contains(mgnayin_wx)) {
                this.juxu = k;
                this.juname = v + "局";
            }
        }
        if (this.cd % this.juxu == 0) {
            this.zwindex = (this.cd / this.juxu + 2) % 12;
        } else {
            int quzheng = this.juxu - (this.cd % this.juxu);
            double shang = Math.ceil((double) this.cd / this.juxu);
            this.zwindex = (int) ((quzheng % 2 == 1) ? (shang - quzheng + 12 + 2) % 12 : (shang + quzheng + 2) % 12);
        }
    }

    public void get_zhengxing() {
        int zwindex = this.zwindex;
        int ji_x = (zwindex + 11) % 12;
        int yang_x = (zwindex + 9) % 12;
        int wuqu_x = (zwindex + 8) % 12;
        int tong_x = (zwindex + 7) % 12;
        int lian_x = (zwindex + 4) % 12;
        int tfindex = (18 - zwindex) % 12;
        int yin_x = (tfindex + 1) % 12;
        int lang_x = (tfindex + 2) % 12;
        int ju_x = (tfindex + 3) % 12;
        int xiang_x = (tfindex + 4) % 12;
        int liang_x = (tfindex + 5) % 12;
        int sha_x = (tfindex + 6) % 12;
        int po_x = (tfindex + 10) % 12;
        List<Integer> zwxingxi = Arrays.asList(zwindex, ji_x, yang_x, wuqu_x, tong_x, lian_x);
        List<Integer> tfxingxi = Arrays.asList(tfindex, yin_x, lang_x, ju_x, xiang_x, liang_x, sha_x, po_x);
        int k = 0;
        for (String v : this.zwxing_s) {
            Integer key = zwxingxi.get(k);
            LinkedHashMap<String, String> hashMap = new LinkedHashMap<>();
            hashMap.put("id", String.valueOf(k));
            hashMap.put("0", this.se_pre1 + v + this.se_end);
            hashMap.put("1", this.se_pre1 + this.zwxing_x.get(k) + this.se_end);
            hashMap.put("2", this._set_mwpx("zw", k));
            hashMap.put("3", this._set_sihua("zw", k));
            this.zwxing.put(key, hashMap);
            k++;
        }
        int i = 0;
        for (String v : this.tfxing_s) {
            Integer key = tfxingxi.get(i);
            LinkedHashMap<String, String> hashMap = new LinkedHashMap<>();
            hashMap.put("id", String.valueOf(i));
            hashMap.put("0", this.se_pre1 + v + this.se_end);
            hashMap.put("1", this.se_pre1 + this.tfxing_x.get(i) + this.se_end);
            hashMap.put("2", this._set_mwpx("tf", i));
            hashMap.put("3", this._set_sihua("tf", i));
            this.tfxing.put(key, hashMap);
            i++;
        }
    }

    public LinkedHashMap<Integer, LinkedHashMap<String, String>> get_zwxing() {
        return this.zwxing;
    }

    public LinkedHashMap<Integer, LinkedHashMap<String, String>> get_tfxing() {
        return this.tfxing;
    }

    public void get_hourx() {
        int wenc_x = (12 - this.hzx) % 12;
        int wenq_x = (this.hzx + 4) % 12;
        int dkong_x = (wenc_x + 1) % 12;
        int djie_x = (11 + this.hzx) % 12;
        int taif_x = (this.hzx + 6) % 12;
        int haox_x = (this.hzx + 2) % 12;
        List<Integer> hourxingxi = Arrays.asList(wenc_x, wenq_x, dkong_x, djie_x, taif_x, haox_x);
        this.hourx = this.array_ique_val(hourxingxi, "hourx", Arrays.asList(0, 1), Arrays.asList(0, 1));
    }

    public void get_monthx() {
        int zuof_x = (4 + this.cm) % 12;
        int youb_x = (12 - this.cm) % 12;
        int txing_x = (9 + this.cm) % 12;
        int tyao_x = (this.cm + 1) % 12;
        int wu = this.cm % 4;
        int twu_x;
        if (wu == 1) {
            twu_x = 6;
        } else if (wu == 2) {
            twu_x = 9;
        } else if (wu == 3) {
            twu_x = 0;
        } else {
            twu_x = 3;
        }
        List<Integer> tyuearr = Arrays.asList(3, 11, 6, 5, 3, 8, 4, 0, 8, 3, 7, 11);
        int tyue_x = tyuearr.get(this.cm % 12);
        List<Integer> yinshaarr = Arrays.asList(5, 3, 1, 11, 9, 7, 5, 3, 1, 11, 9, 7);
        int yinsha_x = yinshaarr.get(this.cm % 12);
        List<Integer> monxingxi = Arrays.asList(zuof_x, youb_x, txing_x, tyao_x, tyue_x, twu_x, yinsha_x);
        this.monthx = this.array_ique_val(monxingxi, "monthx", Arrays.asList(0, 1), Arrays.asList(0, 1));
    }

    public void get_yganx() {
        List<Integer> ganlu = Arrays.asList(1, 3, 4, 6, 7, 6, 7, 9, 10, 0);
        int luc_x = ganlu.get(this.ytgx);
        this.luindex = luc_x;
        int qingy_x = (luc_x + 1) % 12;
        int tuol_x = (luc_x + 11) % 12;
        LinkedHashMap<Integer, List<Integer>> tianyigui = new LinkedHashMap<Integer, List<Integer>>() {{
            put(1, Arrays.asList(2, 8));
            put(5, Arrays.asList(2, 8));
            put(7, Arrays.asList(2, 8));
            put(2, Arrays.asList(1, 9));
            put(6, Arrays.asList(1, 9));
            put(3, Arrays.asList(0, 10));
            put(4, Arrays.asList(0, 10));
            put(8, Arrays.asList(7, 3));
            put(9, Arrays.asList(4, 6));
            put(0, Arrays.asList(4, 6));
        }};
        int tkui_x = tianyigui.get(this.ytgx).get(0);
        int tyue_x = tianyigui.get(this.ytgx).get(1);
        ArrayList<List<Integer>> tianguanfu = new ArrayList<List<Integer>>() {{
            add(Arrays.asList(7, 6));
            add(Arrays.asList(8, 10));
            add(Arrays.asList(5, 9));
            add(Arrays.asList(6, 1));
            add(Arrays.asList(3, 0));
            add(Arrays.asList(4, 4));
            add(Arrays.asList(10, 3));
            add(Arrays.asList(0, 7));
            add(Arrays.asList(10, 6));
            add(Arrays.asList(11, 7));
        }};
        int tguan_x = tianguanfu.get(this.ytgx).get(0);
        int tfu_x = tianguanfu.get(this.ytgx).get(1);
        ArrayList<List<Integer>> kongshen_arr = new ArrayList<List<Integer>>() {{
            add(Arrays.asList(1, 2));
            add(Arrays.asList(9, 10));
            add(Arrays.asList(7, 8));
            add(Arrays.asList(5, 6));
            add(Arrays.asList(3, 4));
        }};
        List<Integer> kongx = kongshen_arr.get(this.ytgx % 5);
        int jluzk_x = Boolean.parseBoolean(String.valueOf(this.ytgx % 2)) ? kongx.get(0) : kongx.get(1);
        int jlufk_x = Boolean.parseBoolean(String.valueOf(this.ytgx % 2)) ? kongx.get(1) : kongx.get(0);
        List<Integer> yearxingxi = Arrays.asList(luc_x, qingy_x, tuol_x, tyue_x, tkui_x, tfu_x, tguan_x, jluzk_x, jlufk_x);
        this.yganx = this.array_ique_val(yearxingxi, "yganx", Arrays.asList(0, 1, 2, 3, 4), Arrays.asList(0));
    }

    public void get_yzhix() {
        int tde_x = (9 + this.ydzx) % 12;
        int txu_x = (6 + this.ydzx) % 12;
        int dahao_x = Boolean.parseBoolean(String.valueOf(this.ydzx % 2)) ? (txu_x + 1) % 12 : (txu_x + 11) % 12;
        int tku_x = (20 - this.ydzx) % 12;
        int tkong_x = (this.ydzx + 1) % 12;
        int longc_x = (4 + this.ydzx) % 12;
        int fengge_x = (12 - this.ydzx) % 12;
        int hluan_x = (17 - this.ydzx) % 12;
        int txi_x = (hluan_x + 6) % 12;
        int jies_x = (12 - this.ydzx) % 12;
        int tma_x = (this.jiang_x + 2) % 12;
        int taoh_x = (this.jiang_x + 9) % 12;
        int jiesa_x = (this.jiang_x + 5) % 12;
        int huag_x = (this.jiang_x + 4) % 12;
        int guchen_x = ((int)(Math.floor(this.ydzx / 3.0) + 1) * 3 % 12);
        int guaxiu_x = ((int)(Math.floor(this.ydzx / 3.0 + 1) * 3 + 8) % 12);
        List<Integer> feilian = Arrays.asList(2, 9, 10, 11, 6, 7, 8, 3, 4, 5, 0, 1);
        int feilian_x = feilian.get(this.ydzx);
        int posui_x = 0;
        if (this.ydzx % 3 == 1) posui_x = 6;
        if (this.ydzx % 3 == 0) posui_x = 10;
        if (this.ydzx % 3 == 2) posui_x = 2;
        List<Integer> yzxingxi = Arrays.asList(txu_x, tku_x, tkong_x, longc_x, fengge_x, taoh_x, hluan_x, txi_x, tma_x, jies_x, huag_x, guchen_x, guaxiu_x, jiesa_x, feilian_x, posui_x, dahao_x);
        this.yzhix = this.array_ique_val(yzxingxi, "yzhix", Collections.singletonList(10000), Collections.emptyList());
    }

    public void get_qitax() {
        int huox_x,xiaoxian;
        if (this.ydzx % 4 == 3) {
            huox_x = (this.hzx + 1) % 12;
            xiaoxian = 4;
        } else if (this.ydzx % 4 == 2) {
            huox_x = (this.hzx + 3) % 12;
            xiaoxian = 7;
        } else if (this.ydzx % 4 == 1) {
            huox_x = (this.hzx + 2) % 12;
            xiaoxian = 10;
        } else {
            huox_x = (this.hzx + 9) % 12;
            xiaoxian = 1;
        }
        this.xiaoxian = xiaoxian;
        int lingx_x = (this.ydzx % 4 == 3) ? (this.hzx + 3) % 12 : (this.hzx + 10) % 12;
        int zuof_x = (3 + this.cm) % 12;
        int sant_x = (zuof_x + this.cd) % 12;
        int youb_x = (23 - this.cm) % 12;
        int bazuo_x = (youb_x - ((this.cd - 1) % 12) + 13) % 12;
        int wenc_x = (12 - this.hzx) % 12;
        int wenq_x = (this.hzx + 4) % 12;
        int eng_x = (wenc_x + this.cd + 10) % 12;
        int tgui_x = (wenq_x + this.cd + 10) % 12;
        int tcai_x = (this.mgindex + this.ydzx - 1) % 12;
        int tshou_x = (this.sgindex + this.ydzx - 1) % 12;
        int tshi = (this.mgindex - 5 + 12) % 12;
        int tsang = (this.mgindex - 7 + 12) % 12;
        int tshi_x = this.is_sun ? tshi : tsang;
        int tsang_x = this.is_sun ? tsang : tshi;
        List<Integer> qtxingxi = Arrays.asList(huox_x, lingx_x, sant_x, bazuo_x, tgui_x, eng_x, tcai_x, tshou_x, tshi_x, tsang_x);
        this.qitax = this.array_ique_val(qtxingxi, "qitax", Collections.singletonList(0), Collections.emptyList());
    }

    private LinkedHashMap<Integer, List<String>> array_ique_val(List<Integer> xing_array, String xtype, List<Integer> mwp_k , List<Integer> sihua_k)
    {
        List<String> sarray = Collections.emptyList();
        List<String> xarray = Collections.emptyList();
        if(xtype.equals("hourx")){
            sarray = this.hourx_s;
            xarray = this.hourx_x;
        }
        if(xtype.equals("monthx")){
            sarray = this.monthx_s;
            xarray = this.monthx_x;
        }
        if(xtype.equals("yganx")){
            sarray = this.yganx_s;
            xarray = this.yganx_x;
        }
        if(xtype.equals("yzhix")){
            sarray = this.yzhix_s;
            xarray = this.yzhix_x;
        }
        if(xtype.equals("qitax")){
            sarray = this.qitax_s;
            xarray = this.qitax_x;
        }
        List<Integer> newList = new ArrayList<>(new HashSet<>(xing_array));
        int i=0;
        LinkedHashMap<Integer,List<String>> res= new LinkedHashMap<>();
        for (String v : sarray) {
            Integer xu = xing_array.get(i);
            if(res.containsKey(xu)){
                List<String> list = res.get(xu);
                String s1 = (mwp_k.isEmpty() || mwp_k.contains(i)) ? this._set_mwpx(xtype, i) : "&emsp;";
                String s2 = (!mwp_k.isEmpty() && mwp_k.contains(i)) ? this._set_sihua(xtype, i) : "&emsp;";
                list.set(0,list.get(0)+v);
                list.set(1,list.get(1)+xarray.get(i));
                list.set(2,list.get(2)+s1);
                list.set(3,list.get(3)+s2);

                res.put(xu,list);
            }else{
                res.put(xu,Arrays.asList(v,xarray.get(i),(mwp_k.isEmpty() || mwp_k.contains(i))?this._set_mwpx(xtype, i) : "&emsp;",(!mwp_k.isEmpty() && mwp_k.contains(i))?this._set_sihua(xtype, i) : "&emsp;"));
            }
            i++;
        }
        return res;
    }

    private String _set_sihua(String xtype,int k) {
        List<String> sihua = Arrays.asList("禄", "权", "科", "忌");
        LinkedHashMap<String,LinkedHashMap<Integer,String>> sihuaname = new LinkedHashMap<String,LinkedHashMap<Integer,String>>(){{
            put("zw", new LinkedHashMap<Integer,String>(){{
                put(0 ,"紫");
                put(1 ,"机");
                put(2 ,"阳");
                put(3 ,"武");
                put(4 ,"同");
                put(5 ,"廉");
            }});
            put("tf",new LinkedHashMap<Integer,String>(){{
                put(1 ,"阴");
                put(2 ,"贪");
                put(3 ,"巨");
                put(5 ,"梁");
                put(7 ,"破");
            }});
            put("hourx",new LinkedHashMap<Integer,String>(){{
                put(0,"昌");
                put(1,"曲");
            }});
            put("monthx",new LinkedHashMap<Integer,String>(){{
                put(0,"辅");
                put(1,"弼");
            }});
        }};
        LinkedHashMap<Integer,List<List<String>>> huaarr = new LinkedHashMap<Integer,List<List<String>>>(){{
                put(0 ,new ArrayList<List<String>>(){{add(Arrays.asList("tf", "7")); add(Arrays.asList("tf", "3")); add(Arrays.asList("tf", "1")); add(Arrays.asList("tf", "2"));}});
                put(1 ,new ArrayList<List<String>>(){{add(Arrays.asList("zw", "5")); add(Arrays.asList("tf", "7")); add(Arrays.asList("zw", "3")); add(Arrays.asList("zw", "2"));}});
                put(2 ,new ArrayList<List<String>>(){{add(Arrays.asList("zw", "1")); add(Arrays.asList("tf", "5")); add(Arrays.asList("zw", "0")); add(Arrays.asList("tf", "1"));}});
                put(3 ,new ArrayList<List<String>>(){{add(Arrays.asList("zw", "4")); add(Arrays.asList("zw", "1")); add(Arrays.asList("hourx", "0")); add(Arrays.asList("zw", "5"));}});
                put(4 ,new ArrayList<List<String>>(){{add(Arrays.asList("tf", "1")); add(Arrays.asList("zw", "4")); add(Arrays.asList("zw", "1")); add(Arrays.asList("tf", "3"));}});
                put(5 ,new ArrayList<List<String>>(){{add(Arrays.asList("tf", "2")); add(Arrays.asList("tf", "1")); add(Arrays.asList("monthx", "1")); add(Arrays.asList("zw", "1"));}});
                put(6 ,new ArrayList<List<String>>(){{add(Arrays.asList("zw", "3")); add(Arrays.asList("tf", "2")); add(Arrays.asList("tf", "5")); add(Arrays.asList("hourx", "1"));}});
                put(7 ,new ArrayList<List<String>>(){{add(Arrays.asList("zw", "2")); add(Arrays.asList("zw", "3")); add(Arrays.asList("tf", "1")); add(Arrays.asList("zw", "4"));}});
                put(8 ,new ArrayList<List<String>>(){{add(Arrays.asList("tf", "3")); add(Arrays.asList("zw", "2")); add(Arrays.asList("hourx", "1")); add(Arrays.asList("hourx", "0"));}});
                put(9 ,new ArrayList<List<String>>(){{add(Arrays.asList("tf", "5")); add(Arrays.asList("zw", "0")); add(Arrays.asList("monthx", "0")); add(Arrays.asList("zw", "3"));}});
        }};
        String name = "&emsp;";

        List<List<String>> yhua = huaarr.get(this.ytgx);
        int key=0;
        for (List<String> val : yhua) {
            if(Objects.equals(val.get(0), xtype) && k == Integer.parseInt(val.get(1))){
                name = sihua.get(key);
                this.sihuaname += sihuaname.get(xtype).get(k);
                break;
            }
            key++;
        }
        return name;
    }

    private String _set_mwpx(String xtype,int  xmxu) {
        String mwpx = "&emsp;";
        for (List<Object> val : this.mpx) {
            if(val.get(0) == xtype && (int)val.get(1) == xmxu){
                int xu = (int) val.get(this.cm + 1);
                mwpx = (xu<0) ? "&emsp;" : this.mpxzi.get(xu);
            }
        }
        return mwpx;
    }

    public LinkedHashMap<Integer, String> get_boshi() {
        LinkedHashMap<Integer, String> map = new LinkedHashMap<>();
        for (int i = 0; i <= 11; i++) {
            int xu = this.is_sun ? (this.luindex + i) % 12 : (this.luindex + 12 - i) % 12;
            map.put(xu,"<font color=blue>"+ this.boshi.get(i)+ "</font>");
        }
        return map;
    }

    public LinkedHashMap<Integer, String> get_changsheng() {
        LinkedHashMap<Integer,Integer> changsheng_arr = new LinkedHashMap<Integer,Integer>(){{
            put(2 ,9);
            put(3 ,0);
            put(4 ,6);
            put(5 ,9);
            put(6 ,3);
        }};
        LinkedHashMap<Integer, String> changshen = new LinkedHashMap<>();
        int changsh_x = changsheng_arr.get(this.juxu);
        boolean cs_sn = true;
        if (this.csmode == 2 && this.ytgx % 2 == 0) cs_sn = false;
        else if(this.csmode == 3 && this.sex == 0) cs_sn = false;
        for (int i = 0; i <= 11; i++) {
            int csx = cs_sn ? (i + changsh_x) % 12 : (changsh_x - i + 12) % 12;
            changshen.put(csx,this.changsheng.get(i).length() < 3 ? this.changsheng.get(i) : "&emsp;"+this.changsheng.get(i));
        }
        return changshen;
    }

    LinkedHashMap<Integer, String> get_daxian() {
        int xushuig = this.mgindex;
        int xushui = this.juxu;
        LinkedHashMap<Integer, String> nsui = new LinkedHashMap<>();
        for (int i = 0; i <= 11; i++) {
            int k = this.is_sun ? (i + xushuig) % 12 : (xushuig - i + 12) % 12;
            String qz = xushui+ "-"+ (xushui + 9);
            int length = qz.length();
            StringBuilder str = new StringBuilder();
            for (int j=0;j<length;j++){
                str.append("&ensp;");
            }
            nsui.put(k,str+qz);
            xushui++;
            xushui += 9;
        }
        return nsui;
    }

    LinkedHashMap<Integer, String> get_yzjiang() {
        LinkedHashMap<Integer, String> jiang = new LinkedHashMap<>();
        for (int i = 0; i <= 11; i++) {
            jiang.put((this.jiang_x + i) % 12,  "<font color=brown>"+this.liunianxing2.get(i)+ "</font>");
        }
        return jiang;
    }

    public LinkedHashMap<Integer, String> get_xiaoxian() {
        LinkedHashMap<Integer,String> xxian = new LinkedHashMap<>();
        for (int i = 0; i <= 11; i++) {
           int  k = Boolean.parseBoolean(String.valueOf(this.sex)) ? (this.xiaoxian + i) % 12 : (this.xiaoxian - i + 12) % 12;
            xxian.put(k , (i + 1)+ " "+ (i + 6)+ " "+ (i + 11)+ " "+ (i + 16));
        }
        LinkedHashMap<Integer,String> xiaoxiangong = new LinkedHashMap<>();
        for (int i = 0; i <= 11; i++) {
            xiaoxiangong.put((this.ydzx + i) % 12 , " <font color=brown>"+ this.liunianxing.get(i)+ "</font>");
        }
        return xiaoxiangong;
    }

    public String[] pai_zwpan() {
        LinkedHashMap<Integer, String> tp0 = new LinkedHashMap<>();
        LinkedHashMap<Integer, String> tp1 = new LinkedHashMap<>();
        LinkedHashMap<Integer, String> tp2 = new LinkedHashMap<>();
        LinkedHashMap<Integer, String> tp3 = new LinkedHashMap<>();
        for (int i = 0; i <= 11; i++) {
            if (!this.zwxing.containsKey(i)) {
                this.zwxing.put(i,new LinkedHashMap<String,String>(){{
                    put("0", "");
                    put("1", "");
                    put("2", "");
                    put("3", "");
                }});
            }
            if(!this.tfxing.containsKey(i)){
                this.tfxing.put(i,new LinkedHashMap<String,String>(){{
                    put("0", "");
                    put("1", "");
                    put("2", "");
                    put("3", "");
                }});
            }
            if(!this.yganx.containsKey(i)){
                this.yganx.put(i,Arrays.asList("","","",""));
            }
            if(!this.yzhix.containsKey(i)){
                this.yzhix.put(i,new ArrayList<String>(){{
                    add("");
                    add("");
                    add("");
                    add("");
                }});
            }
            if(!this.monthx.containsKey(i)){
                this.monthx.put(i,new ArrayList<String>(){{
                    add("");
                    add("");
                    add("");
                    add("");
                }});
            }
            if(!this.hourx.containsKey(i)){
                this.hourx.put(i,new ArrayList<String>(){{
                    add("");
                    add("");
                    add("");
                    add("");
                }});
            }
            if(!this.qitax.containsKey(i)){
                this.qitax.put(i,new ArrayList<String>(){{
                    add("");
                    add("");
                    add("");
                    add("");
                }});
            }
            System.out.println(this.tfxing);
            System.out.println(this.tfxing.get(i));
            tp0.put(i,this.zwxing.get(i).get("0")+ this.tfxing.get(i).get("0")+ this.monthx.get(i).get(0)+ this.hourx.get(i).get(0)+ this.yganx.get(i).get(0)+ this.yzhix.get(i).get(0)+ this.qitax.get(i).get(0));
            tp1.put(i,this.zwxing.get(i).get("1")+ this.tfxing.get(i).get("1")+ this.monthx.get(i).get(1)+ this.hourx.get(i).get(1)+ this.yganx.get(i).get(1)+ this.yzhix.get(i).get(1)+ this.qitax.get(i).get(1));
            tp2.put(i,this.zwxing.get(i).get("2")+ this.tfxing.get(i).get("2")+ this.monthx.get(i).get(2)+ this.hourx.get(i).get(2)+ this.yganx.get(i).get(2)+ this.yzhix.get(i).get(2)+ this.qitax.get(i).get(2));
            tp3.put(i,this.zwxing.get(i).get("3")+ this.tfxing.get(i).get("3")+ this.monthx.get(i).get(3)+ this.hourx.get(i).get(3)+ this.yganx.get(i).get(3)+ this.yzhix.get(i).get(3)+ this.qitax.get(i).get(3));
        }
        LinkedHashMap<Integer, String> boshis = this.get_boshi();
        LinkedHashMap<Integer, String> nsui = this.get_daxian();
        LinkedHashMap<Integer, String> yzjiang = this.get_yzjiang();
        LinkedHashMap<Integer, String> xiaoxian = this.get_xiaoxian();
        LinkedHashMap<Integer, String> changshen = this.get_changsheng();
        String[] pan = new String[12];


        for (int i = 0; i <= 11; i++) {
            String str = tp0.get(i)+ "<br>"+tp1.get(i)+ "<br>"+tp2.get(i)+ "<br>"+tp3.get(i)+ "<br>"+boshis.get(i)+"<br>"+yzjiang.get(i)+ "&emsp;"+nsui.get(i)+ "&emsp;"+changshen.get(i)+ "<br>" + xiaoxian.get(i)+ "&emsp;"+ this.minggong.get(i)+ "&emsp;"+ this.dptg.get(i)+ this.se_pre +this.dizhi.get(i)+ this.se_end;
            pan[i] = str;
        }
        return pan;
    }


    public String get_zwju_name() {
        return this.juname;
    }

    public String get_sihua_name() {
        return this.sihuaname;
    }

    public LinkedHashMap<String, String> get_doujun() {
        Calendar instance = Calendar.getInstance();
        int year = instance.get(Calendar.YEAR);
        int liunian = (year - 1912) % 12;
        int doujunx = (((liunian - this.cm + 13) % 12) + this.hzx + 1) % 12;
        int zidoux = (this.hzx - this.cm + 13) % 12;
        LinkedHashMap<String, String> res = new LinkedHashMap<>();
        res.put("zd", this.dizhi.get(zidoux));
        res.put("dj", this.dizhi.get(doujunx));
        return res;
    }

    public String get_mgongz() {
        return this.dizhi.get(this.mgindex);
    }

    public String get_mingzhu() {
        List<String> mingzhuarr = Arrays.asList("巨门", "贪狼", "巨门", "禄存", "文曲", "廉贞", "武曲", "破军", "武曲", "廉贞", "文曲", "禄存");
        return mingzhuarr.get(this.mgindex);
    }

    public String get_sgongz() {
        return this.dizhi.get(this.sgindex);
    }

    public String get_shenzhu() {
        List<String> shenzhuarr = Arrays.asList("天机", "铃星", "天相", "天梁", "天同", "文昌", "天机", "火星", "天相", "天梁", "天同", "文昌");
        return shenzhuarr.get(this.ydzx);
    }

    private String get_nayin_wx(int gx, int zx) {
        List<String> wx = Arrays.asList("土", "木", "金", "水", "火");
        gx = gx == 0 ? 10 : gx;
        double gs = Math.floor(gx / 2.0) + gx % 2;
        int z = zx % 6 == 0 ? 6 : zx % 6;
        double zs = Math.ceil((double) z / 2);
        int x = (int) ((gs + zs) % 5);
        return wx.get(x);
    }

    private List<Integer> ygzkong()
    {
        ArrayList<List<Integer>> kong = new ArrayList<>();
        kong = new ArrayList<List<Integer>>(){{add(Arrays.asList(0, 11)); add(Arrays.asList(9, 10)); add(Arrays.asList(7, 8)); add(Arrays.asList(5, 6)); add(Arrays.asList(3, 4)); add(Arrays.asList(1, 2));}};
        int gx = this.ytgx == 0 ? 10 : this.ytgx;
        int xu = (12 + this.ydzx - gx) % 12;
        for (List<Integer> v : kong) {
            if(v.contains(xu)){
                return v;
            }
        }
        return Collections.emptyList();
    }

}
